from tornado.ioloop import IOLoop
from tornado import gen
from protocol.py.protocol.Rpc import Client
from thrift import Thrift
from torthrift.pool import TStreamPool
from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory
from torthrift.client import PoolClient

@gen.coroutine
def test():
    try:
        transport = TStreamPool('127.0.0.1', 20000, max_stream=10)
        client = PoolClient(Client, transport, TBinaryProtocolFactory())

        for i in range(1, 10):
            res = yield client.call("hello")
            print(res)
        
        # yield client.close()
    except Thrift.TException as ex:
        print("%s" % (ex.message))
    ioloop.stop()

ioloop = IOLoop.instance()
ioloop.add_callback(test)
ioloop.start()
